package com.ybkj.daijia.server.scheduler;

import com.ybkj.daijia.server.model.Company;
import com.ybkj.daijia.server.model.Driver;
import com.ybkj.daijia.server.service.CompanyService;
import com.ybkj.daijia.server.service.DriverService;
import com.ybkj.daijia.server.service.SuperviceService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 30s定时上传驾驶员和车辆位置信息
 *
 * @author Administrator
 */
@Component
public class UpPosition {

    @Autowired
    private DriverService driverService;
    @Autowired
    private SuperviceService superviceService;
    @Autowired
    private CompanyService companyService;

    @Transactional(rollbackFor = Exception.class)
    public void sjwzMessage() {
        // 保持vpn活性
        try {
            Company company = companyService.getMain();
            Long registeredVehiclesNumber = company.getRegisteredVehiclesNumber();
            if (registeredVehiclesNumber == null || registeredVehiclesNumber == 0) {
                company.setRegisteredVehiclesNumber(Long.valueOf(200));
            }
            Long registeredDriverNumber = company.getRegisteredDriverNumber();
            if (registeredDriverNumber == null || registeredDriverNumber == 0) {
                company.setRegisteredDriverNumber(Long.valueOf(200));
            }
            superviceService.vpnLive(company);

            List<Driver> drivers = driverService.listValid(null);

            for (Driver driver : drivers) {

                superviceService.SjwzMessage(driver);

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
